package com.wang.mandkey.activity;

import android.app.Activity;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;

import com.wang.common.exception.Crashandler;
import com.wang.common.exception.Crashandler.CrashCallback;
import com.wang.mandkey.App;
import com.wang.mandkey.R;
import com.wang.mandkey.utils.ProjectEnvironment;
import com.waps.AppConnect;

/**
 * activity
 * 
 * @author wangzy
 * 
 */
public class BaseActivity extends Activity implements
		SoundPool.OnLoadCompleteListener {

	String tag = "";

	@Override
	protected void onStart() {
		super.onStart();
		Crashandler crashHandler = Crashandler.getInstance();
		crashHandler.init(getApplicationContext(), new CrashCallback() {
			@Override
			public void OnCrash() {
				App.exitApp(BaseActivity.this);
			}
		});
	}

	@Override
	public void onBackPressed() {
		finish();
		return;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tag = this.getClass().getSimpleName();
		
		if (ProjectEnvironment.isExit) {
			finish();
		}

		ProjectEnvironment.globalActivitys.add(this);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		ProjectEnvironment.BOOLEAN_LOCK_KEYBOAED = true;

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// return super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_base, menu);

		return true;
	}

	@Override
	public boolean onMenuOpened(int featureId, Menu menu) {
		// 返回true则显示系统系统菜单

		return super.onMenuOpened(featureId, menu);
	}

	/**
	 * 当用户选择了当前ItmeSelected
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

		case R.id.menuItemLock:
			ProjectEnvironment.BOOLEAN_LOCK_KEYBOAED = true;
			break;
		case R.id.menuItemExit:
			App.exitApp(this);
			break;
		case R.id.menuItemUnLock:
			ProjectEnvironment.BOOLEAN_LOCK_KEYBOAED = false;
			break;
		case R.id.menuItemFeedBack:
			AppConnect.getInstance(this).showFeedback();
			break;
		default:
			break;
		}
		return false;
	}

	/**
	 * 初始化视图
	 */
	void setUpView() {

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {

	}
}